class Messager{
    
public:
    MessageImp* m_messageImp;
    Messager(MessageImp* messageImp) : m_messageImp(messageImp){}
//这里应该将子类要使用的对象放在protected中
/*
eg:
protected:
    MessageImp* m_messageImp;
*/
    virtual void Login(string username, string password)=0;
    virtual void SendMessage(string message)=0;
    virtual void SendPicture(Image image)=0;
    virtual ~Messager(){}
};

class MessageImp{
    virtual void PlaySound()=0;
    virtual void DrawShape()=0;
    virtual void WriteText()=0;
    virtual void Connect()=0;
    virtual ~MessageImp();
}


//平台实现

class PCMessagerBase : public MessageImp{
public:
    
    virtual void PlaySound(){
        //**********
    }
    virtual void DrawShape(){
        //**********
    }
    virtual void WriteText(){
        //**********
    }
    virtual void Connect(){
        //**********
    }
};

class MobileMessagerBase : public MessageImp{
public:
    
    virtual void PlaySound(){
        //==========
    }
    virtual void DrawShape(){
        //==========
    }
    virtual void WriteText(){
        //==========
    }
    virtual void Connect(){
        //==========
    }
};



//业务抽象 m

//类的数目 1+n+m 

class MessagerLite : public Messager {
public:
    
    virtual void Login(string username, string password){
        
        m_messageImp->Connect();
        //........
    }
    virtual void SendMessage(string message){
        
        m_messageImp->WriteText();
        //........
    }
    virtual void SendPicture(Image image){
        
        m_messageImp->DrawShape();
        //........
    }
};



class MessagerPerfect : public Messager {
public:
    
    virtual void Login(string username, string password){
        
        m_messageImp->PlaySound();
        //********
        m_messageImp->Connect();
        //........
    }
    virtual void SendMessage(string message){
        
        m_messageImp->PlaySound();
        //********
        m_messageImp->WriteText();
        //........
    }
    virtual void SendPicture(Image image){
        
        m_messageImp->PlaySound();
        //********
        m_messageImp->DrawShape();
        //........
    }
};


void Process(){
    //运时装配
    MessageImp *mi = new PCMessagerBase();
    Messager *m = new PCMessagerLite(mi);
    //实例中写的是Messager *m =new Messager(mImp); 但是我认为都可以，都是运行时装配
}
